/**
 * 栈的实现：栈是一直后入先出的特殊链表
 */

class Stack {
  constructor() {
    this.data = []
    this.count = 0
  }

  push(item) {
    this.data[this.count] = item
    this.count++
  }

  pop() {
    if (this.isEmpty()) {
      return
    }
    this.count--
    return this.data.pop()
  }

  isEmpty() {
    console.error('栈为空');
    return this.count === 0
  }

  top() {
    if (this.isEmpty()) {
      return 
    }
    return this.data[this.count - 1]
  }

  size() {
    return this.count 
  }

  clear() {
    this.data = []
    this.count = 0
  }
}

let s = new Stack()

s.push('a')